package com.yanqu.road.server.cmd.orewar.task;

import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.base.BaseTask;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

public class RobPitTask extends BaseTask {

	private int activityId;

	private int pitId;

	private long pitOwnerUserId;

	private List<Integer> patronsIdList;


	public int getActivityId(){
		return activityId;
	}

	public RobPitTask(YanQuMessage packet, GamePlayer player) {
		super(packet, player);
	}

	@Override
	protected boolean parseData() throws Exception {
		OreWarProto.OrePitRobReqMsg reqMsg = OreWarProto.OrePitRobReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		pitId = reqMsg.getPitId();
		pitOwnerUserId = reqMsg.getPitOwnerUserId();
		patronsIdList = new ArrayList<>();
		for(Integer patronsId : reqMsg.getPatronsIdListList()){
			if(!patronsIdList.contains(patronsId)){
				patronsIdList.add(patronsId);
			}
		}
		return true;
	}

	@Override
	protected void execute() {

	}

	@Override
	protected void sendData(GamePlayer player) {
		OreWarProto.OrePitRobRespMsg.Builder resMsg = OreWarProto.OrePitRobRespMsg.newBuilder();
		resMsg.setRet(ret);
		if(ret == 0){
			long nowTime = System.currentTimeMillis();
			resMsg = OreWarMgr.robPit(player, activityId, pitId, pitOwnerUserId, patronsIdList);
			logger.info("ore battle cost time:{}", System.currentTimeMillis() - nowTime);
		}
		player.sendPacket(Protocol.U_ORE_WAR_ROB_PIT,resMsg);
	}

}
